/*
     Copyright 2007 Joseph M. Ferner

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

using NMock2;
using NUnit.Framework;
using FtpState = OpenServers.Net.FtpServer.State.FtpState;

namespace OpenServers.Net.FtpServer.Command {
    [TestFixture]
    public class TypeCommandTest : AbstractCommandTest<TypeCommand> {
        [Test]
        public void TestInvokeASCII() {
            Expect.Once.On(MockMessages).Method("Get200");

            PrivateObject.WrappedObject.Invoke(MockFtpServer, State, "A");

            Assert.AreEqual(FtpState.Type.TypeEnum.Ascii, State.CurrentType.CurrentType);
            Assert.AreEqual(FtpState.Type.SubTypeEnum.NonPrint, State.CurrentType.SubType);
        }

        [Test]
        public void TestInvokeASCIINonPrint() {
            Expect.Once.On(MockMessages).Method("Get200");

            PrivateObject.WrappedObject.Invoke(MockFtpServer, State, "A N");

            Assert.AreEqual(FtpState.Type.TypeEnum.Ascii, State.CurrentType.CurrentType);
            Assert.AreEqual(FtpState.Type.SubTypeEnum.NonPrint, State.CurrentType.SubType);
        }

        [Test]
        public void TestInvokeASCIITelnet() {
            Expect.Once.On(MockMessages).Method("Get200");

            PrivateObject.WrappedObject.Invoke(MockFtpServer, State, "A T");

            Assert.AreEqual(FtpState.Type.TypeEnum.Ascii, State.CurrentType.CurrentType);
            Assert.AreEqual(FtpState.Type.SubTypeEnum.TelnetFormEffectors, State.CurrentType.SubType);
        }

        [Test]
        public void TestInvokeASCIICarriageControl() {
            Expect.Once.On(MockMessages).Method("Get200");

            PrivateObject.WrappedObject.Invoke(MockFtpServer, State, "A C");

            Assert.AreEqual(FtpState.Type.TypeEnum.Ascii, State.CurrentType.CurrentType);
            Assert.AreEqual(FtpState.Type.SubTypeEnum.CarriageControl, State.CurrentType.SubType);
        }

        [Test]
        public void TestInvokeASCIIBadSubType() {
            Expect.Once.On(MockMessages).Method("Get501");

            PrivateObject.WrappedObject.Invoke(MockFtpServer, State, "A Z");
        }

        [Test]
        public void TestInvokeASCIITooManyArguments() {
            Expect.Once.On(MockMessages).Method("Get501");

            PrivateObject.WrappedObject.Invoke(MockFtpServer, State, "A N Z");
        }

        [Test]
        public void TestInvokeBadType() {
            Expect.Once.On(MockMessages).Method("Get501");

            PrivateObject.WrappedObject.Invoke(MockFtpServer, State, "Z");
        }

        [Test]
        public void TestInvokeEBCDIC() {
            Expect.Once.On(MockMessages).Method("Get200");

            PrivateObject.WrappedObject.Invoke(MockFtpServer, State, "E");

            Assert.AreEqual(FtpState.Type.TypeEnum.Ebcdic, State.CurrentType.CurrentType);
            Assert.AreEqual(FtpState.Type.SubTypeEnum.NonPrint, State.CurrentType.SubType);
        }

        [Test]
        public void TestInvokeEBCDICTooManyArguments() {
            Expect.Once.On(MockMessages).Method("Get501");

            PrivateObject.WrappedObject.Invoke(MockFtpServer, State, "E Z");
        }

        [Test]
        public void TestInvokeImage() {
            Expect.Once.On(MockMessages).Method("Get200");

            PrivateObject.WrappedObject.Invoke(MockFtpServer, State, "I");

            Assert.AreEqual(FtpState.Type.TypeEnum.Image, State.CurrentType.CurrentType);
            Assert.AreEqual(FtpState.Type.SubTypeEnum.NonPrint, State.CurrentType.SubType);
        }

        [Test]
        public void TestInvokeImageTooManyArguments() {
            Expect.Once.On(MockMessages).Method("Get501");

            PrivateObject.WrappedObject.Invoke(MockFtpServer, State, "I Z");
        }


        [Test]
        public void TestInvokeLocalByteSize() {
            Expect.Once.On(MockMessages).Method("Get200");

            PrivateObject.WrappedObject.Invoke(MockFtpServer, State, "L 8");

            Assert.AreEqual(FtpState.Type.TypeEnum.LocalByteSize, State.CurrentType.CurrentType);
            Assert.AreEqual(FtpState.Type.SubTypeEnum.NonPrint, State.CurrentType.SubType);
            Assert.AreEqual(8, State.CurrentType.LocalByteSize);
        }

        [Test]
        public void TestInvokeLocalByteSizeTooManyArguments() {
            Expect.Once.On(MockMessages).Method("Get501");

            PrivateObject.WrappedObject.Invoke(MockFtpServer, State, "L 8 Z");
        }

        [Test]
        public void TestInvokeLocalByteSizeBadSize() {
            Expect.Once.On(MockMessages).Method("Get501");

            PrivateObject.WrappedObject.Invoke(MockFtpServer, State, "L Z");
        }

        [Test]
        public void TestInvokeLocalByteSizeNoSize() {
            Expect.Once.On(MockMessages).Method("Get501");

            PrivateObject.WrappedObject.Invoke(MockFtpServer, State, "L");
        }

        [Test]
        public void TestInvokeNoArguments() {
            Expect.Once.On(MockMessages).Method("Get501");

            PrivateObject.WrappedObject.Invoke(MockFtpServer, State, "");
        }
    }
}
